﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SSN.Objects;
using SSN.Utilities;
using SSN.Utilities.Security;
using SSN.Utilities.Cache;
using SSN.BusinessFramework;
using SSN.BusinessFramework.Documents;

namespace SSN.WebFramework
{
    public class DocumentManager
    {
        #region caching
        private static KeyValueCache<int, Document> _docCache = new KeyValueCache<int, Document>(getDoc, new TimeSpan(4, 0, 0));

        private static Document getDoc(int id)
        {
            Document d = new Document();
            SystemSecurityContext ctx = new SystemSecurityContext();
            if (d.Load(ctx, id))
            {
                return d;
            }

            return null;
        }

        private SSNSecurityContext _ctx;
        
        public void PurgeCache()
        {
            _docCache.Purge(_ctx);
        }
        #endregion

        public DocumentManager(SSNSecurityContext ctx)
        {
            _ctx = ctx;
        }

        public Document GetDocument(int id)
        {
            return _docCache[id];
        }
    }
}
